<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/21
 * Time: 9:47
 *首页产品图相关大图，小图，颜色编辑上传
 */
require('../include/init.inc.php');
$method = $id = $model = $search = $products_id = $products_model = $products_color = $uploadfile = $products_spec_price = '';
extract($_REQUEST, EXTR_IF_EXISTS);

if (Common::isPost()) {
    if ($uploadfile) {
        $img_src = $uploadfile;
    }

    $prod_color = $products_color . "{}" . $img_src . "{}" . $products_spec_price;

    $prod = AdminProducts::getProductById($products_id);

    if(!$prod){
        Common::exitWithError(ErrorMessage::PRODUCT_NOT_EXIST, "one_page_shop/product_add_color.php");
    }

    if ($prod['products_color']) {
        $color_str = $prod['products_color'] . "||" . $prod_color;
    } else {
        $color_str = $prod_color;
    }


    $up_data = array('products_color' => $color_str);
    $where = " WHERE products_id = " . $products_id;

    $ret = AdminProducts::update($where, $up_data);

    if ($ret) {
        SysLog::addLog(UserSession::getUserName(), 'Update', 'ColorAdd', $products_model, json_encode($up_data));
        Common::exitWithSuccess('添加完成', 'one_page_shop/home_product.php');
    } else {
        OSAdmin::alert("error");
    }
}


$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign('osadmin_action_confirm', $confirm_html);
Template::assign('pid', $id);
Template::assign('model', $model);
Template::display('one_page_shop/add_color.tpl');
